package com.ruoyi.web.controller.biz;

import com.ruoyi.common.constant.OSSConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户信息
 *
 * @author zx
 */
@RestController
@RequestMapping("/resource")
public class BizResourceController extends BaseController {
    @Autowired
    private OssUtils ossUtils;

    @GetMapping("/test")
    public void list(SysUser user) {
        System.out.println(11111);
    }


    @RequestMapping("/upload")
    public AjaxResult upload(MultipartFile file) {
        try {
            String fileName = file.getOriginalFilename();
            String key = ossUtils.generateKey(fileName);
            ossUtils.putObject(OSSConstants.CARD, key, file.getInputStream());
            AjaxResult ajax = AjaxResult.success();
            ajax.put("fileName", fileName);
            ajax.put("url", OSSConstants.CARD_URL_PREFIX + key);
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

}
